defmodule ProcessLib do
    @moduledoc false

    def async_do(mod, func, args, _timeout \\ 5000) do
        Task.async(
            fn () ->
                try do
                    {:ok, apply(mod, func, args)}
                rescue
                    err ->
                        err
                catch
                    err ->
                        err
                end
            end
        )
    end

    def memory() do
        Process.spawn(fn () -> :etop.start([{:output, :text}, {:interval, 1}, {:lines, 10}, {:sort, :memory}]) end, [])
    end

    def cpu() do
        Process.spawn(
            fn () -> :etop.start([{:output, :text}, {:interval, 1}, {:lines, 10}, {:sort, :reductions}]) end,
            []
        )
    end

end
